package com.ghsc.ghxc.jsb.ui.message.view

import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.cn.appcore.ext.getCompatColor
import com.cn.appcore.utils.GlideUtil
import com.ghsc.ghxc.jsb.R
import com.ghsc.ghxc.jsb.ui.message.bean.GroupTypeItem
import com.lxj.xpopup.core.BottomPopupView

/**
 * 项目：JingShortVideo
 * 包名：com.bbl.jyShortVideo.ui.video.live.view
 * 类名：LiveAudienceListPopupView
 * 创建时间：2022/12/20 12:25
 * 创建人 @author： xiaolin
 * 描述 ：Todo...   创建群聊的类型
 */
class GroupTypeListPopupView  (context: AppCompatActivity, mList :MutableList<GroupTypeItem>, tvBtnSub:(item:GroupTypeItem)->Unit,) : BottomPopupView(context) {
    private val mContext = context
    override fun getImplLayoutId() = R.layout.live_audience_list
    private var tvBtnSub: (item:GroupTypeItem) -> Unit = tvBtnSub
    var mList = mList
    val mAdapter = ListAdapter()

    override fun onCreate() {
        super.onCreate()
        findViewById<TextView>(R.id.tvTitl).text="选择分类"
        var  rvList= findViewById<RecyclerView>(R.id.rvList)
        rvList.layoutManager = LinearLayoutManager(mContext)
        rvList.adapter = mAdapter
        mAdapter.replaceData(mList)
        mAdapter.setOnItemClickListener { adapter, view, position ->
            tvBtnSub.invoke( mAdapter.getItem(position)!!)
            dismiss()
        }
    }
    override fun onDestroy() {
        super.onDestroy()
    }
    override fun getMaxWidth() = 0
    class ListAdapter  : BaseQuickAdapter<GroupTypeItem, BaseViewHolder>(
        R.layout.gropu_type_item) {
        override fun convert(helper: BaseViewHolder, item: GroupTypeItem) {
            GlideUtil.ImageLoad(this.context,  item.un_checked_icon, helper.getView(R.id.imgIcon))
            helper.setText(R.id.tvName,item.title)
                .setTextColor(R.id.tvName,if(item.isSelect) this.context.getCompatColor( R.color.main_color) else this.context.getCompatColor( R.color.font_black))
                .setGone(R.id.isCheck, !item.isSelect)


        }
    }
}